package netty.learning.demo.application;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class FileTextReader {

    public static List<String> getTextList(String fileName){

        List<String> list = new ArrayList<>();
        try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName)),
                "UTF-8"))) {
            for(String lineText = bufferedReader.readLine(); lineText != null; lineText=bufferedReader.readLine() ){
                list.add(lineText);
            }
            //System.out.println(list);
        } catch ( IOException e) {
            e.printStackTrace();
        }
        return list;
    }

    public static String getText(String fileName){
        List<String> list = getTextList(fileName);
        StringBuilder textBuilder  = new StringBuilder();
        for(String text: list){
            textBuilder.append(text.trim());
        }
        return textBuilder.toString();
    }



    public static void main(String[] args) {

        String fileName = "C:\\Users\\xhf\\Desktop\\test.json";
        System.out.println(getText(fileName));

    }
}
